package com.qmx.qmxapp.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.qmx.qmxapp.R;
import com.qmx.qmxapp.base.BaseActivity;
import com.qmx.qmxapp.bean.ContactModel;
import com.qmx.qmxapp.constant.AppConstant;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;

import static com.qmx.qmxapp.R.id.browse_sql;
import static com.qmx.qmxapp.R.id.ci_head_icon;

public class ContactDetailActivity extends BaseActivity {
    @BindView(R.id.ci_head_icon)
    CircleImageView ci_head_icon;
    @BindView(R.id.rv_name)
    RelativeLayout rv_name;
    @BindView(R.id.tv_name)
    TextView tv_name;
    @BindView(R.id.rv_video)
    RelativeLayout rv_video;
    @BindView(R.id.tv_video)
    TextView tv_video;
    @BindView(R.id.rv_video_phone)
    RelativeLayout rv_video_phone;
    @BindView(R.id.tv_video_number)
    TextView tv_video_number;
    @BindView(R.id.rv_call_phone)
    RelativeLayout rv_call_phone;
    @BindView(R.id.tv_phone_number)
    TextView tv_phone_number;

    private Gson mGson = new Gson();
    private String data;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_contact_datail);
        ButterKnife.bind(this);

        initView();

    }

    private void initView() {
        data = this.getIntent().getStringExtra("content");
        ContactModel.Content.Users users = mGson.fromJson(data, ContactModel.Content.Users.class);
        tv_name.setText(users.getName());
        tv_video_number.setText(String.valueOf(users.getRoom_id()));
        tv_phone_number.setText(users.getMobile());
        loadIcon(users.getAvatar());
    }

    private void loadIcon(String avatar) {
        Glide.with(this).load(AppConstant.Url + avatar).into(ci_head_icon);
    }


    @OnClick({R.id.rv_video, R.id.rv_video_phone, R.id.rv_call_phone})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rv_video:

                break;
            case R.id.rv_video_phone:

                break;
            case R.id.rv_call_phone:
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_CALL);
                intent.setData(Uri.parse("tel:" + tv_phone_number.getText().toString()));
                startActivity(intent);
                break;
        }
    }
}
